package cz.muni.fi.pa165.musiclibrary.implejb.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

import org.apache.commons.lang3.Validate;
import org.joda.time.LocalDate;

import cz.muni.fi.pa165.musiclibrary.api.database.dao.IAlbumDAO;
import cz.muni.fi.pa165.musiclibrary.api.database.entity.IAlbum;
import cz.muni.fi.pa165.musiclibrary.api.service.dto.IAlbumDTO;
import cz.muni.fi.pa165.musiclibrary.implejb.service.dto.translator.AlbumDTOTranslator;


/**
 *
 * @author Maros Kucbel
 * @date 2012-11-09T20:30:55+0100
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class AlbumService implements AlbumServiceLocal {

    private IAlbumDAO albumDao;
    
    @EJB
    public void setAlbumDao(final IAlbumDAO albumDao) {
        this.albumDao = albumDao;
    }
    
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Override
    public void create(IAlbumDTO album) {
        Validate.isTrue(album != null, "Album should not be null.");
        final IAlbum entity = AlbumDTOTranslator.translateFromDTO(album);
        this.albumDao.create(entity);
    }

    @Override
    public void update(IAlbumDTO album) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void delete(IAlbumDTO album) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public IAlbumDTO getById(Long id) {
        Validate.isTrue(id != null, "Identifier should not be null.");
        final IAlbum entity = this.albumDao.getById(id);
        return AlbumDTOTranslator.translateToDTO(entity);
    }

    @Override
    public List<IAlbumDTO> getAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<IAlbumDTO> getByTitle(String title) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<IAlbumDTO> getByReleaseDate(LocalDate date) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
